<?php
class Category {
	private $CI;
	// DB VALUES
	public $category_id;
	public $name;
    public $oreder;
	// DB	
	function __construct() {
		$this->CI =& get_instance();
	}
	
	public function update() {
		$data = array(
			'category_id' => $this->category_id,
            'name' => $this->name,
            'order' => $this->order
        );
		
		$this->CI->db->where('category_id', $this->category_id);
		$res = $this->CI->db->update(TABLE_CATEGORIES, $data);
		
		if (!$res) {
		  $msg = $this->db->_error_message();
		  //$num = $this->db->_error_number();
		  KLogger::Instance()->logDebug("Category->update() sql error: " + $msg);
		}
	}
	
	public function delete() {
		$res = $this->CI->db->delete(TABLE_CATEGORIES, array('category_id' => $this->category_id));
		
		if (!$res) {
		  $msg = $this->db->_error_message();
		  //$num = $this->db->_error_number();
		  
		  KLogger::Instance()->logDebug("Category->delete() sql error: " + $msg);
		}
	}

	public function upload() {
		$data = array(
            'category_id' => $this->category_id,
            'name' => $this->name,
			'order' => $this->order
        );

		$this->CI->db->insert(TABLE_CATEGORIES, $data);
	}
}


class EmptyCategory extends Category {
	public $name = "NINCS";
}
?>